package com.thingsgrid.device.controller;

import com.thingsgrid.device.entity.Shadow;
import com.thingsgrid.device.service.IShadowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.sql.Timestamp;
import java.util.List;

@RestController
//@AllArgsConstructor
@RequestMapping("/shadow")
@Api(value = "", tags = "接口")
public class ShadowController {
	@Autowired
	private IShadowService shadowService;
	/**
	 * 新增
	 */
	@PostMapping("/submit")
	@ApiOperation(value = "新增", notes = "传入shadow", position = 1)
	public void save(@Valid @RequestBody Shadow shadow) {
		shadowService.saveShadow(shadow);
	}

	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperation(value = "逻辑删除", notes = "传入ids", position = 2)
	public void remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		shadowService.removeShadow(ids);
	}

	/**
	 * 修改
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "传入shadow", position = 3)
	public void update(@Valid @RequestBody Shadow shadow) {
		shadowService.updateShadow(shadow);
	}

	/**
	 * 查找所有
	 */
	@GetMapping("/selectAll")
	@ApiOperation(value = "查询所有", notes = "", position = 4)
	public R<List<Shadow>> selectAll() {
		//productService.updateProduct(product);
		return R.data(shadowService.findAll());
	}
	/**
	 * 根据id查信息
	 */
	@GetMapping("/detail")
	@ApiOperation(value = "查询一个", notes = "", position = 5)
	public Shadow selectById(@ApiParam(value = "productId", required = true) @RequestParam String ids) {
		//productService.updateProduct(product);
		return shadowService.findShadowById(ids);
	}
	/**
	 * 分页查询
	 */
//	@GetMapping("/list")
//	@ApiOperation(value = "分页", notes = "传入页数和每页显示的条数", position = 6)
//	public List<Product> pageList(@ApiParam(value = "页数和条数", required = true)
//								  @RequestParam Integer current, Integer size){
//		return productService.findAll(current,size);
//
//	}

	/**
	 * 用户列表
	 */
	@GetMapping("/list")
	@ApiOperation(value = "列表", notes = "传入account和realName", position = 2)
	public R<List<Shadow>> pageList(@ApiParam(value = "页数和条数", required = true)
									 @RequestParam Integer current, Integer size){
		return R.data(shadowService.findAll(current,size));

	}


//	public R<IPage<Product>> list(@ApiIgnore @RequestParam Map<String, Object> product, Query query, BladeProduct bladeUser) {
//		QueryWrapper<User> queryWrapper = Condition.getQueryWrapper(user, User.class);
//		IPage<User> pages = userService.page(Condition.getPage(query), (!bladeUser.getTenantCode().equals(BladeConstant.ADMIN_TENANT_CODE)) ? queryWrapper.lambda().eq(User::getTenantCode, bladeUser.getTenantCode()) : queryWrapper);
//		UserWrapper userWrapper = new UserWrapper(userService, dictClient);
//		return R.data(userWrapper.pageVO(pages));
//	}

	/**
	 * 可变参数查询
	 */
	@GetMapping("/selectByCondition")
	@ApiOperation(value = "根据条件查",notes = "可变条件",position = 7)
	public R<List<Shadow>> selectByCondition(@Valid @RequestBody String shadowName, String shadowType, Timestamp beginTime, Timestamp endTime,
                                             Integer isPublish){
		return R.data(shadowService.selectByCondition(shadowName, shadowType, beginTime, endTime,
			isPublish));
	}

}
